package com.ewhale.feitengguest.widget;

import android.app.Dialog;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.View;
import android.view.Window;

import com.ewhale.feitengguest.R;

import androidx.annotation.NonNull;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class ShareDialog extends Dialog {

    private int shareType = -1;
    private onItemClickListener mListener;
    public ShareDialog(@NonNull Context context) {
        super(context, com.simga.library.R.style.Dialog);
        this.setCanceledOnTouchOutside(true);
        setContentView(R.layout.dialog_share);
        ButterKnife.bind(this);
    }

    @Override
    protected void onStart() {
        super.onStart();
        Window window = getWindow();
        DisplayMetrics dm = new DisplayMetrics();
        window.getWindowManager().getDefaultDisplay().getMetrics(dm);
        window.setLayout(dm.widthPixels, window.getAttributes().height);
        window.setGravity(Gravity.BOTTOM);
        window.setWindowAnimations(R.style.bottom_int_out_dialog_style);
        window.setBackgroundDrawable(new ColorDrawable(0x00000000));
    }

    @OnClick({R.id.tv_qq, R.id.tv_wechat, R.id.btn_cancel})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_qq:
                shareType = 1;
                break;
            case R.id.tv_wechat:
                shareType = 2;
                break;
            default:
                shareType = -1;
                break;
        }
        if (mListener != null && shareType != -1) {
            mListener.onClick(shareType);
        }
        dismiss();
    }

    public void setOnItemClickListener(onItemClickListener listener) {
        mListener = listener;
    }

    public interface onItemClickListener {

        void onClick(int type);

    }
}
